<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ page pageEncoding="utf-8"%>
<%request.setCharacterEncoding("utf-8");%>
<%@include file="/include/currentuserinfo.jsp"%>
<%@include file="/include/pageexpires.jsp"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <META content="MSHTML 6.00.2800.1561" name=GENERATOR>
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    
    <title>易讯消息</title>
    <link type="text/css" rel="stylesheet" href="<%=ctxpath%>/themes/newstyle/styles/mac/macmenu.css" id="menuStyleSheet">
    <link rel="STYLESHEET" type="text/css" href="<%=ctxpath%>/dhtmlxTree/css/dhtmlXTree.css">
    <script  src="<%=ctxpath%>/dhtmlxTree/javascript/dhtmlXCommon.js"></script>
    <script  src="<%=ctxpath%>/dhtmlxTree/javascript/dhtmlXTree.js"></script>
    <script type="text/javascript" src="<%=ctxpath%>/chat/js/dtree.js"></script>
    <script src="<%=ctxpath%>/chat/js/prototype.js" type="text/javascript"></script>
    <script src="<%=ctxpath%>/chat/js/ricobase.js" type="text/javascript"></script>
    <script src="<%=ctxpath%>/chat/js/ricoeffects.js" type="text/javascript"></script>
    <script src="<%=ctxpath%>/chat/js/ricobehaviors.js" type="text/javascript"></script>
    <script src="<%=ctxpath%>/chat/js/ricocomponents.js" type="text/javascript"></script>
    
  </head>
  <%
  com.ecomm.chat.manager.ChatUserInfoManager.getInstance().updateChatUserInfoOnlineStateS(userid,"1");
  //oncontextmenu="return false;"
  %>
  <body onLoad="shuaxin()" oncontextmenu="return false;" onunload="leavesys()" id="body">
    <SCRIPT LANGUAGE="JavaScript1.2" >
      //onbeforeunload="leavesys()"
      function leavesys(){
      var url = '<%=ctxpath%>/chat/ajaxcheck.do?method=updateSysState&state=0&userid=<%=userid%>';
      httpRequestGroupdo(url);
     // alert(url);
      //window.close();
      }
      var menuskin = "skin1"; 
      var display_url = 0; 
      var chatid;
      function showmenuie5(ccid) {
      chatid = ccid;
      var rightedge = document.body.clientWidth-event.clientX;
      var bottomedge = document.body.clientHeight-event.clientY;
      if (rightedge < ie5menu.offsetWidth)
      ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth;
      else
      ie5menu.style.left = document.body.scrollLeft + event.clientX;
      if (bottomedge < ie5menu.offsetHeight)
      ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight;
      else
      ie5menu.style.top = document.body.scrollTop + event.clientY;
      ie5menu.style.visibility = "visible";
      return false;
      }
      function hidemenuie5() {
      ie5menu.style.visibility = "hidden";
      }
      function highlightie5() {
      if (event.srcElement.className == "menuitems") {
      event.srcElement.style.backgroundColor = "highlight";
      event.srcElement.style.color = "white";
      if (display_url)
      window.status = event.srcElement.url;
         }
      }
      function lowlightie5() {
      if (event.srcElement.className == "menuitems") {
      event.srcElement.style.backgroundColor = "";
      event.srcElement.style.color = "black";
      window.status = "";
         }
      }
   function openChatList()
    {
        window.open('<%=ctxpath%>/chat/message.do?method=search&flag=1','openChatList','status=no,resizable=yes,scrollbars=no,toolbar=no,WIDTH=550,HEIGHT=400');

    }   
    function opendGroup(){
        window.open("<%=ctxpath%>/chat/groupfind.do?method=find&id="+chatid,"Group", "status=no,resizable=yes,scrollbars=no,toolbar=no,WIDTH=500,HEIGHT=270");
        }
       function newGroup(id){
        window.open("<%=ctxpath%>/chat/groupfind.do?method=find&id="+id,"Group", "status=no,resizable=yes,scrollbars=no,toolbar=no,WIDTH=500,HEIGHT=270");
        }
      function deleteGroup(){
      var url='<%=ctxpath%>/chat/group/delete.do?method=delete&id='+chatid;
      httpRequestGroupdo(url);
       reloadChat();
      }
   function reloadChat(){
   window.document.location.reload();
   }
  function httpRequestGroupdo(url)
    {
          var req;
     if (window.XMLHttpRequest) {
         req = new XMLHttpRequest();
     }else if (window.ActiveXObject) {
         req = new ActiveXObject("Microsoft.XMLHTTP");
     }
    if(req){
        req.open("GET", url, true);
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        req.setRequestHeader("Content-Type","text/html"); 
        req.setRequestHeader("Content-Type","utf-8");
        req.send(null);  
     }	
    }
      function opend(id){
      var bool = tree.getUserData(id,'isuser');
       if (bool == 'true'){
          window.open("<%=ctxpath%>/chat/frameset.jsp?nick=<%=userid%>&id="+id,id, "status=no,resizable=yes,scrollbars=no,toolbar=no,WIDTH=500,HEIGHT=450")
         }
        }
      function opendGroupChat(id,groupid){
        window.open("<%=ctxpath%>/chat/frameset.jsp?nick=<%=userid%>&id="+id+"&groupid="+groupid,id, "status=no,resizable=yes,scrollbars=no,toolbar=no,WIDTH=500,HEIGHT=450")
      }
      function tonghuahistory(){
        window.open("<%=ctxpath%>/chat/message/iframeMessage.jsp","history", "status=no,resizable=yes,scrollbars=no,toolbar=no,WIDTH=710,HEIGHT=550")
      }
      function pingtaixitong(){
      	window.open("<%=ctxpath%>/themes/newstyle/index.jsp","pingtaixitong", "status=yes,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,titlebar=yes,location=yes,WIDTH=960,HEIGHT=740")
      }
      function changepassword(){
        window.open("<%=ctxpath%>/chat/config/changepassword.jsp","changepassword", "status=no,resizable=yes,scrollbars=no,toolbar=no,WIDTH=430,HEIGHT=150")
      }        
      function remind(){
        window.open("<%=ctxpath%>/chat/remind/saveorupdate.do?method=find&userid=<%=userid%>","remind", "status=no,resizable=yes,scrollbars=no,toolbar=no,WIDTH=400,HEIGHT=200")
      }    //  
    //刷新 开始  
     setInterval("shuaxin()", 60000);
      
      function shuaxin(){ 
        chatCountid();
        memberCountid();
        chatWindowOpen();
        chatSound();
      }
      function chatWindowOpen(){
      var url = '<%=ctxpath%>/chat/ajaxcheck.do?method=getChatWindowOpen&userid=<%=userid%>';
      httpRequestChatWindowOpen(url);
      }
      function chatSound(){
      var url = '<%=ctxpath%>/chat/ajaxcheck.do?method=getChatSound&userid=<%=userid%>';
      httpRequestChatSound(url);
      }
      
      function chatCountid(){
      var url = '<%=ctxpath%>/chat/ajaxcheck.do?method=getChatCount&userid=<%=userid%>';
      httpRequestchatdo(url);
      }

     function memberCountid(){
      var url = '<%=ctxpath%>/chat/ajaxcheck.do?method=getMemberCount';
      httpRequestMemberdo(url);
      }
      
   function httpRequestChatSound(url){
           var req;
     if (window.XMLHttpRequest) {
         req = new XMLHttpRequest();
     }else if (window.ActiveXObject) {
         req = new ActiveXObject("Microsoft.XMLHTTP");
     }
    if(req){
          req.onreadystatechange=function() {  
           if (req.readyState==4 && req.status==200) {//判断状态，4是已发送，200已完成  
             var  nickName = req.responseText;
             if(nickName != '0'){
              document.getElementById("ChatSound").innerHTML = nickName;
             }else{
              document.getElementById("ChatSound").innerHTML = "";
             }
         }  
         }
        req.open("GET", url, true);
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        req.setRequestHeader("Content-Type","text/html");  
        req.setRequestHeader("Content-Type","utf-8");  
        req.send(null);  
     }	
 
 }
 function httpRequestChatWindowOpen(url){
           var req;
     if (window.XMLHttpRequest) {
         req = new XMLHttpRequest();
     }else if (window.ActiveXObject) {
         req = new ActiveXObject("Microsoft.XMLHTTP");
     }
    if(req){
          req.onreadystatechange=function() {  
           if (req.readyState==4 && req.status==200) {//判断状态，4是已发送，200已完成  
             var  nickName = req.responseText;
             if(nickName != '0'){
             //alert(nickName);
             openChatList();
             }
         }  
         }
        req.open("GET", url, true);
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        req.setRequestHeader("Content-Type","text/html");  
        req.setRequestHeader("Content-Type","utf-8");  
        req.send(null);  
     }	
 
 }
 function httpRequestchatdo(url)
    {
          var req;
     if (window.XMLHttpRequest) {
         req = new XMLHttpRequest();
     }else if (window.ActiveXObject) {
         req = new ActiveXObject("Microsoft.XMLHTTP");
     }
    if(req){
          req.onreadystatechange=function() {  
           if (req.readyState==4 && req.status==200) {//判断状态，4是已发送，200已完成  
             var  nickName = req.responseText;
             ChatRemind(nickName);
         }  
         }
        req.open("GET", url, true);
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        req.setRequestHeader("Content-Type","text/html");  
        req.setRequestHeader("Content-Type","utf-8");  
        req.send(null);  
     }	
    }	


 function ChatRemind(countid) {
       // alert("你有"+countid+"条消息");
        if(countid != '0'){
        initPopup(countid); 
        document.getElementById("ChatCount").innerHTML = countid;
        }else{
        document.getElementById("ChatCount").innerHTML = "0";
        }
}
  function membertxt(countid){
      //alert("在线："+countid+"人");
      if(countid != '0'){
        document.getElementById("memberCount").innerHTML = countid;
        }else{
        document.getElementById("memberCount").innerHTML = "0";
        }
    }
 function httpRequestMemberdo(url)
    {
          var req;
     if (window.XMLHttpRequest) {
         req = new XMLHttpRequest();
     }else if (window.ActiveXObject) {
         req = new ActiveXObject("Microsoft.XMLHTTP");
     }
    if(req){
          req.onreadystatechange=function() {  
           if (req.readyState==4 && req.status==200) {//判断状态，4是已发送，200已完成  
             var  nickName = req.responseText;
             membertxt(nickName);
         }  
         }
        req.open("GET", url, true);
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        req.setRequestHeader("Content-Type","text/html");  
        req.setRequestHeader("Content-Type","utf-8");  
        req.send(null);  
     }	
    }
    /**
function m_func(state,id,tree,value){
  if((state==2)&&(value!S="")){
    alert(id);
    alert(value);
    }
    if ((state==2)&&(value=="")) return false;
    return true;
    }
    */
    </script>
    <table width="100%" border="0" cellpadding="0" cellspacing="2">
      <tr >
        <td class="chat_topdiv_otd"><div class="chat_topdiv">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td rowspan="2" class="chat_bigren_otd">&nbsp;</td>
                <td nowrap class="chat_nametd"><%=username%>
                  <%				  
                  // com.ecomm.chat.pojo.ChatUserInfo cuichat = com.ecomm.chat.manager.ChatUserInfoManager.getInstance().getChatUserInfoByUserid(userid);
                  // if(cuichat != null){
                  //   out.print(cuichat.getChatdesc());
                  //  }
                  %>
                </td>
                <td class="chat_refrensh"><img src="<%=ctxpath%>/chat/images/refrensh.gif" alt="刷新" width="16" height="16" border="0" onClick="reloadChat()">&nbsp;</td>
              </tr>
              <tr>
                <td class="chat_wellcome">欢迎您！</td>
                <td align="right"><table border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td nowrap>
                        <table border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td><img src="<%=ctxpath%>/chat/images/newmessage.gif" alt="新消息" width="15" height="11" hspace="2" border="0" align="absmiddle"></td>
                            <td>(</td>
                            <td><a href="#" onClick="openChatList()"><div id="ChatCount" ><%=com.ecomm.chat.manager.ChatRemindManager.getInstance().getRemindCount(userid)%></div></a></td>
                            <td>)</td>
                          </tr>
                      </table></td>
                      <td>&nbsp;&nbsp;</td>
                      <td nowrap>
                        <table border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td><img src="<%=ctxpath%>/chat/images/onlineren.gif" alt="在线人数" width="13" height="16" hspace="2" border="0" align="absmiddle"></td>
                            <td>(</td>
                            <td><div id="memberCount" ><%=com.ecomm.chat.manager.ChatUserInfoManager.getInstance().getMemberCount("1")%></div></td>
                            <td>)</td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                </table></td>
              </tr>
            </table>
        </div></td>
      </tr>
      <%
      String id = request.getParameter("id");
      if(id== null || id.equals("")){
        id="";
      }
      %>
      <tr >
        <td><div >
            <div  id="accordionExample">
              <div >
                <div class="panelheader">部门人员</div>
                <div class="panelContent">
                  <!--   <a href="javascript:void(0);" onclick="tree.editItem(tree.getSelectedItemId(),true);">编辑</a>
                                     <br><br>-->
                  <div id="treeboxbox_tree" style="width:100%;height:100%"></div>
                  <script>
			tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%","<%=id%>");
			tree.setImagePath("<%=ctxpath%>/chat/img/");
                        tree.setOnClickHandler(opend);
                        //tree.enableItemEditor(true);
                        //tree.setEditStartAction(true,true);
                       // tree.setOnEditHandler(m_func);
                        tree.setXMLAutoLoading("<%=ctxpath%>/tree/DhtmlxTree/orgmodle.do?method=getChatUser");
                        tree.loadXML("<%=ctxpath%>/tree/DhtmlxTree/orgmodle.do?method=getChatUser&id=<%=id%>");
                  </script>  
                </div>
              </div>
              <div >
                <div class="panelheader"> 我的群组 </div>
                <div class="panelContent">
                  <script type="text/javascript">
                  dd = new dTree('dd');
                   dd.add('00000001','-1','<a href=\"#\" onclick=\"newGroup(\'00000001\')\" >新建群组</a>');
                  <% 
                  com.ecomm.chat.manager.ChatGroupManager chatGroupManager = com.ecomm.chat.manager.ChatGroupManager.getInstance();
                  java.util.ArrayList al_Group = (java.util.ArrayList)chatGroupManager.getGroupTree(userid);
                  if(al_Group != null && al_Group.size() >0){
                    for(int i = 0;i<al_Group.size();i++){
                      com.ecomm.chat.pojo.ChatGroup chatGroup = (com.ecomm.chat.pojo.ChatGroup)al_Group.get(i);
                    
                  %>
                   dd.add('<%=chatGroup.getId()%>','00000001','<a href=\"#\" oncontextmenu = \"showmenuie5(\'<%=chatGroup.getId()%>\')\" onclick=\"opendGroupChat(\'<%=chatGroup.getId()%>\',\'<%=chatGroup.getId()%>\')\" > <%=chatGroup.getGroupname()%></a>','','<%=ctxpath%>/chat/img/folclose.gif','<%=ctxpath%>/chat/img/folopen.gif');
                  <%
                  if(chatGroup.getGroupmember() != null) {
                        String[] userids = chatGroup.getGroupmember().split(",");
                        
                        for(int j = 0;j<userids.length;j++){
                      %>
                   dd.add('<%=userids[j]%>','<%=chatGroup.getId()%>','<a href=\"#\" onclick=\"opend(\'<%=userids[j]%>\')\" ><%=com.ecomm.util.CommonMethod.getUserNameByUserID(userids[j])%></a>','','<%=ctxpath%>/chat/img/folclose.gif','<%=ctxpath%>/chat/img/folopen.gif','<%=ctxpath%><%=com.ecomm.chat.manager.ChatUserInfoManager.getInstance().getchatUserInfo(userids[j])%>');   
                <%
                              }
                  }
                    }
                  }

              %>
                   document.write(dd);
                   //-->
                  </script>
                </div>
              </div>
              <div>
                <div class="panelheader"> 系统设置 </div>
                <div class="panelContent">
                  <table align="center">
                    <tr>
                      <td align="center"><img src="<%=ctxpath%>/chat/images/mimaxiugai.gif" width="64" height="40" vspace="4" title="修改密码" ><br>
                      <a href="#"  onClick="changepassword()"> 修改密码</a> </td>
                    </tr>
                    <tr>
                      <td align="center"><img src="<%=ctxpath%>/chat/images/shezhi.gif" width="64" height="61" vspace="4"  title="个人信息设置"  ><br>
                      <a href="#" onClick="remind()">个人信息设置</a> </td>
                    </tr>
                    <tr>
                      <td align="center"><img src="<%=ctxpath%>/chat/images/tonghuajilu.gif" width="64" height="40" vspace="4" title="通话记录"  ><br>
                      <a href="#" onClick="tonghuahistory()">聊天记录 </a> </td>
                    </tr>
                    
                  </table>
                </div>
              </div>
              <!-- 
              <div>
                <div class="panelheader">
                  其它
                </div>
                <div class="panelContent">
                  可以为流程消息提醒方式
                </div>
              </div>
              -->
            </div>
          </div>
          <script> new Rico.Accordion( $$('div.panelheader'), $$('div.panelContent'), 
								{panelHeight:460,
								 hoverClass: 'panelHover',
								 selectedClass: 'panelSelected'});
          </script>
        </td>
      </tr>
    </table>
    <!--添加图层提醒-->
    <SCRIPT language=JavaScript>
     var timePopup=5;
    var ns=(document.layers);
    var ie=(document.all);
    var w3=(document.getElementById && !ie);
   var adCount=0;
    function initPopup(countid)
    {
        if(!ns && !ie && !w3)
            return;
        if(ie)
           adDiv = document.all.lbplocation.style;
        else if(ns) adDiv=eval('document.layers["lbplocation"]');
        else if(w3) adDiv=eval('document.getElementById("lbplocation").style');
        if (ie||w3)
        {
            adDiv.visibility="visible";
        }
        else
        {
            adDiv.visibility ="show";
        }
        if(countid != '' && countid != '0'){
        showPopup();
        document.all.num.value=countid;
        }
    }
    function showPopup()
    {
        if(adCount<timePopup*10)
        {
            adCount+=1;
            if (ie)
            {
                documentWidth  =document.body.offsetWidth/2+document.body.scrollLeft-20;
                documentHeight =document.body.offsetHeight/2+document.body.scrollTop-20;
            }
            else if (ns)
            {
                documentWidth=window.innerWidth/2+window.pageXOffset-20;documentHeight=window.innerHeight/2+window.pageYOffset-20;
            }
            else if (w3)
            {
                documentWidth=self.innerWidth/2+window.pageXOffset-20;documentHeight=self.innerHeight/2+window.pageYOffset-20;
            }
            //adDiv.left=documentWidth-250;
            //adDiv.top =documentHeight-150;
            adDiv.left=document.body.offsetWidth-180;
            adDiv.top =0;
            setTimeout("showPopup()",100);
          //  onload=initPopup;
        }
        else closePopup();
    }

    function closePopup()
    {
       adCount=0;
        if (ie||w3)
            document.all.lbplocation.style.visibility="hidden";
        else
            adDiv.visibility ="hide";
    }

    function showAlert(num)
    {
       initPopup();
       document.all.num.value=num;
       //document.all.atd.value=num;
    }
                        </SCRIPT>
    <div id="ChatSound" style="display:none"></div>
    
    <DIV id=lbplocation style="LEFT: 55%; POSITION: absolute; TOP: 50px; VISIBILITY: hidden; width: 200;">
      <TABLE class="Titus">
        <TBODY>
          <tr>
            <td class="gao"></td>
          </tr>
          <TR>
            
            <TD ><table border="0" cellspacing="0" cellpadding="0" class="xx">
                <tr>
                  <td class="xjl"></td>
                  <td  class="Titus_font_1">信息提示</td>
                  <td >&nbsp;&nbsp;</td>
                  <td> <A href="javascript:openChatList();" title=从这里开始进入消息列表><IMG src="<%=ctxpath%>/images/rtxoff.GIF" /></A></td>
                </tr>
            </table></TD>
          </TR>
          <TR>
            
            <TD class="Titus_font_2">您有  <INPUT name="num" type="text" class="input_Titus" id="num" VALUE="0" size="3">条新消息</TD>
          </TR>
          <TR>
            
            <TD align=middle vAlign=center class="Titus_5">(此视窗将于 5 秒后自动关闭)</TD>
          </TR>
        </TBODY>
      </TABLE>
    </DIV>
    
    <div id="ie5menu" class="skin0" onMouseover="highlightie5()" onMouseout="lowlightie5()">
      <div class="menuitems" onClick="opendGroup();">  修改群组  </div>
      <div class="menuitems" onClick="deleteGroup();">  删除群组  </div>
    </div>
    
    <script language="JavaScript1.2">
      if (document.all && window.print) {
          ie5menu.className = menuskin;
          document.body.onclick = hidemenuie5;
      }
    </script>
    
  </body>
</html>
